tests: Use readdir64 when _FILE_OFFSET_BITS set
authorDan Nicholson <nicholson@endlessm.com>
Wed, 3 Jun 2015 19:34:37 +0000 (12:34 -0700)
committerColin Walters <walters@verbum.org>
Thu, 4 Jun 2015 22:56:31 +0000 (18:56 -0400)
On 32 bit systems, _FILE_OFFSET_BITS will be set to 64 by
AC_SYS_LARGEFILE. This causes the glibc headers to use readdir64 rather
than readdir. Emulate that behavior in the preloader or the tests will
all fail with "No such file or directory".

tests/readdir-rand.c

index bf37b111d6ea5372ea3733b71263d358d17a5744..527d4a3a0945b2757f25be4bc12b500263672ce3 100644 (file)
 #include <sys/stat.h>
 #include <glib.h>
 
+/* Glibc uses readdir64 when _FILE_OFFSET_BITS == 64 as set by
+ * AC_SYS_LARGEFILE on 32 bit systems.
+ */
+#if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64)
+# define READDIR "readdir64"
+# define READDIR_R "readdir64_r"
+#else
+# define READDIR "readdir"
+# define READDIR_R "readdir_r"
+#endif
+
 static GHashTable *direntcache;
 static GMutex direntcache_lock;
 static gsize initialized;
@@ -69,7 +80,7 @@ ensure_initialized (void)
 struct dirent *
 readdir (DIR *dirp)
 {
-  struct dirent *(*real_readdir)(DIR *dirp) = dlsym (RTLD_NEXT, "readdir");
+  struct dirent *(*real_readdir)(DIR *dirp) = dlsym (RTLD_NEXT, READDIR);
   struct dirent *ret;
   gboolean cache_another = TRUE;
   
@@ -186,7 +197,7 @@ rewinddir (DIR *dirp)
 int
 readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result)
 {
-  int (*real_readdir_r)(DIR *dirp, struct dirent *entry, struct dirent **result) = dlsym (RTLD_NEXT, "readdir_r");
+  int (*real_readdir_r)(DIR *dirp, struct dirent *entry, struct dirent **result) = dlsym (RTLD_NEXT, READDIR_R);
 
   ensure_initialized ();